using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BindLightToCamera : MonoBehaviour
{
    public Transform mainCamera;
    [SerializeField]
    private float yOffset = -25f;
    // Update is called once per frame
    void Update()
    {
        if (null == mainCamera && Camera.main)
        {
            mainCamera = Camera.main.transform;
            
        }
        
        if (null == mainCamera)
        {
           
            Camera[] cs = GameObject.FindObjectsOfType<Camera>();
            
            foreach (var c in cs)
            {
                Debug.Log(c.tag);
                if (c.tag.Contains("MainCamera"))
                {
                    mainCamera = c.transform;
                    break;
                }
            }
            

        }
        var eulerAngles = this.transform.rotation.eulerAngles;
        eulerAngles.y = mainCamera.rotation.eulerAngles.y + yOffset;
        this.transform.rotation = Quaternion.Euler(eulerAngles);

    }
}
